home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / screen-profiles / network-down < prev    next >
Encoding:
Text File  |  2009-04-08  |  1.4 KB  |  40 lines

  1. #!/bin/sh -e
  2. #
  3. #    network-down: calculate the network receive rate
  4. #    Copyright (C) 2008 Canonical Ltd.
  5. #
  6. #    Authors: Dustin Kirkland <kirkland@canonical.com>
  7. #
  8. #    This program is free software: you can redistribute it and/or modify
  9. #    it under the terms of the GNU General Public License as published by
  10. #    the Free Software Foundation, version 3 of the License.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. cache="$HOME/.screen-profiles/network-down"
  21. interface=`route -n | tail -n 1 | sed "s/^.* //"`
  22. unit="kB/s"
  23.  
  24. t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
  25. t2=`date +%s`
  26.  
  27. if [ $t2 -le $t1 ]; then
  28.     rate=0
  29. else
  30.     x1=`cat "$cache"` 2>/dev/null || tx1=0
  31.     x2=`ifconfig "$interface" | grep "RX bytes" | sed "s/^.*RX bytes://" | sed "s/ .*$//"`
  32.     echo "$x2" > "$cache"
  33.     rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
  34.     if [ "$rate" -gt 1024 ]; then
  35.         rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
  36.         unit="MB/s"
  37.     fi
  38. fi
  39. printf "v\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} "
  40.